package cn.gd.controller.Meetingroombookings;

import cn.gd.pojo.Announcements;
import cn.gd.pojo.MeetingroombookingTool.MeetingroombookingVo;
import cn.gd.pojo.Meetingroombookings;
import cn.gd.pojo.Meetingrooms;
import cn.gd.service.Announcements.AnnouncementService;
import cn.gd.service.Meetingroombookings.MeetingRoomBookingService;
import cn.gd.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wyh
 * @version 1.80
 */

@CrossOrigin
@RestController
@RequestMapping("/meetingRoomBooking")
public class MeetingRoomBookingController {
    @Autowired
    private MeetingRoomBookingService meetingRoomBookingService;

    @GetMapping("/getMeetingRoomBookingAll/{pageNo}/{pageSize}")
    public Result<PageInfo<Meetingroombookings>> getMeetingRoomBookingAll(@PathVariable Integer pageNo,
                                                                          @PathVariable Integer pageSize,
                                                                          @RequestBody(required = false) MeetingroombookingVo meetingroombookingVo) {
        return Result.ok(meetingRoomBookingService.getMeetingRoomBookingAll(meetingroombookingVo,pageNo, pageSize));
    }

    @PostMapping("/getMeetingRoomAll/{pageNo}/{pageSize}")
    public Result<PageInfo<Meetingrooms>> getMeetingRoomAll(@PathVariable Integer pageNo,
                                                            @PathVariable Integer pageSize,
                                                            @RequestBody(required = false)
                                                                MeetingroombookingVo
                                                                        meetingroombookingVo) {
        return Result.ok(meetingRoomBookingService.getMeetingRoomAll(meetingroombookingVo,pageNo, pageSize));
    }

    @PostMapping("/addMeetingRoomBooking")
    public Result<Map<String, String>> addMeetingRoomBooking(@RequestBody Meetingroombookings meetingroombookings) {
        int num = meetingRoomBookingService.addMeetingRoomBooking(meetingroombookings);
        Map<String, String> map = new HashMap<>();
        if (num > 0) {
            map.put("result", "true");
        } else {
            map.put("result", "false");
        }
        return Result.ok(map);
    }

    @DeleteMapping("/deleteMeetingRoomBooking/{id}")
    public Result<Map<String, String>> deleteMeetingRoomBooking(@PathVariable  Integer id) {
        int num = meetingRoomBookingService.deleteMeetingRoomBooking(id);
        Map<String, String> map = new HashMap<>();
        if (num > 0) {
            map.put("result", "true");
        } else {
            map.put("result", "false");
        }
        return Result.ok(map);
    }
}
